/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    var meetNum = GetQueryString("meetNum");
    var type = GetQueryString("type");

    var sel = $.Params.create();
    sel.addParams("page", 0);
    sel.addParams("rows", rows);
    sel.addParams("meetNum", meetNum);
    sel.addParams("type", type);
    getData();

    //查询
    $("#searchBtn").on("click", function () {
        var pTitle = $("#pTitle").val();
        if (pTitle != "") {
            sel.addParams("pTitle", pTitle);
        } else {
            sel.addParams("pTitle", undefined);
        }
        getData();
    })

    //判断checkbox状态
    $("#selAll").on("click", function () {
        if (!$(this).attr("checked")) {
            $("input[type=checkbox]").attr("checked", "checked")
        } else {
            $("input[type=checkbox]").removeAttr("checked");
        }
    })

    //添加事件
    $('#addBtn').on("click", function () {
        window.location.href = "pfMemberAdd.html?meetNum=" + meetNum + "&type=" + type;
    });
    //删除事件
    $('#delBtn').on("click", function () {
        var params = getCheckData();
        if (params != "") {
            if (confirm("确定要删除吗！")) {
                var del = $.Params.create();
                //del.addParams("params", params)
                del.ajax("delete", getAdminIP() + "pfMembers?params=" + params, function (data) {
                    if (data.success) {
                        alert("删除成功！");
                        getData();
                    }
                })
            }
        } else {
            alert("请至少选中一项");
        }
    });


    //获取数据
    function getData() {
        getPageData("get", sel, getAdminIP() + "pfMembers", function (data) {
            if (data.success) {
                var html = "";
                if (data.total > 0) {
                    $.each(data.result, function (i, val) {
                        html += "<tr role='row'' class='even'>" +
                            "<td><input eid='" + val.id + "' onclick='getCheck(this)' type='checkbox' class='classOption'></td>" +
                            "<td class='sorting_1'>" + val.name + "</td>" +
                            "<td>" + val.tel + "</td>" +
                            "<td>" + val.hospitalName + "</td>" +
                            "<td><button type='button' class='btn btn-primary'  onclick='getPf(\"" + val.openId + "\",\"" + meetNum + "\")'>查看评分</button></td>" +
                            "<td>" + val.createTime + "</td>" +
                            "<td><button type='button' class='btn btn-primary'  onclick='updateInfo(\"" + val.id + "\")'>修改</button></td>" +
                            "</tr>";
                    });
                } else {
                    html = "<tr><td>暂无数据</td></tr>"
                }
                $("#listContainer").html(html);

            }
        })
    }
    updateInfo = function (eid) {
        window.location.href = "pfMemberUpdate.html?eid=" + eid + "&meetNum=" + meetNum + "&type=" + type;
    }
});
function getPf(openId, meetNum) {
    window.location.href = "pfJudgeList.html?openId=" + openId + "&meetNum=" + meetNum;
}


